package recite.word.client.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import recite.word.client.dto.search.SearchAddOne;
import recite.word.client.dto.search.SearchListDTO;
import recite.word.client.service.ISearchService;
import recite.word.client.vo.search.SearchListVO;
import recite.word.service.base.common.request.BaseRequest;
import recite.word.service.base.common.response.ResponseResult;

import java.util.List;

@RestController
@RequestMapping("/client/search")
@Api(tags = "客户端【搜索】controller")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    /**
     * 模糊搜索单词
     * @return
     */
    @PostMapping("/getSearchList")
    public ResponseResult<List<SearchListVO>> getSearchList(@RequestBody BaseRequest<SearchListDTO> dto){
        List<SearchListVO> ans = searchService.getSearchList(dto);
        return ResponseResult.success(ans);
    }

    /**
     * 查询历史记录(默认前8条)
     */
    @PostMapping("/getHistory")
    public ResponseResult<List<SearchListVO>> getHistory() {
        List<SearchListVO> ans = searchService.getHistory();
        return ResponseResult.success(ans);
    }

    /**
     * 点击具体搜索单词
     */
    @PostMapping("/addOne")
    public ResponseResult addOne(@RequestBody BaseRequest<SearchAddOne> dto) {
        searchService.addOne(dto);
        return ResponseResult.success();
    }

    /**
     * 清空历史
     */
    @PostMapping("/cleanHistory")
    public ResponseResult cleanHistory(){
        searchService.cleanHistory();
        return ResponseResult.success();
    }
}
